<template>
  <div>
    <el-table
      :data="bannerList"
      style="width: 100%"
      row-key="id"
      border
      lazy
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="id" label="编号"> </el-table-column>
      <el-table-column prop="title" label="轮播图标题"> </el-table-column>
      <el-table-column  label="图片">
          
          <template slot-scope="scope">
              <div>
                  <img :src="$pre+scope.row.img" alt="" class="im22">
                  
              </div>
          </template> </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scope">
          <div>
            <el-button v-if="scope.row.status == 1" type="danger">
              启用
            </el-button>
            <el-button v-else type="success"> 禁用 </el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="操作">
        <template slot-scope="scope">
          <div>
            <el-button @click="dit(scope.row.id)">编辑</el-button>
            <el-button @click="del(scope.row.id)">删除</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { successAlert, warningAlert } from "../../../util/alter";
import { mapGetters, mapActions } from "vuex";
//引入删除接口
import { bannerDel,bannerList } from "../../../requster/api";

export default {
  data() {
    return {
      arr: [],
    };
  },

  methods: {
    ...mapActions({
      reqbannerlist: "banner/reqChangeList",
    }),

    // 删除事件
    del(id) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          bannerDel({ id: id }).then((res) => {
            if (res.data.code == 200) {
              successAlert(res.data.msg);
              //  重新渲染页面
              this.reqbannerlist();
            } else {
              warningAlert(res.data.msg);
            }
          });
        })
        .catch(() => {
          warningAlert("取消删除");
        });
    },
    // 编辑事件
    dit(id) {
      this.$emit("dit", id);
    },
  },

  computed: {
    ...mapGetters({
      bannerList: "banner/list",
    }),
  },
  mounted() {
    console.log(this.bannerList);
    this.reqbannerlist();
  },
};
</script>

<style>
.im22{
    width: 100px;
    height: 100px;
}
</style>